--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Commit b720efbc175c08179c6139d499da473b0ef7b346
Parents : 9c2754d
Author : Ivan <e46112d44649266d71fe2193e00a4710>
Signature : T66BB85Valid, signed by author
Date : 2026-07-19T04:37:05-05:00
refactor: update identity hash generation in tests to use consistent hex values for improved clarity and reliability
Changes
4 files changed, 25 insertions(+), 16 deletions(-)
Diff
diff --git a/meshchatx.rsm b/meshchatx.rsm
index f93c1534..11ef1008 100644
Binary files a/meshchatx.rsm and b/meshchatx.rsm differ
diff --git a/tests/backend/test_identity_switch.py b/tests/backend/test_identity_switch.py
index 39d8c30b..dde5803b 100644
--- a/tests/backend/test_identity_switch.py
+++ b/tests/backend/test_identity_switch.py
@@ -107,7 +107,7 @@ async def test_hotswap_identity_success(mock_rns, temp_dir):
)
# Setup new identity
- new_hash = "new_hash_123"
+ new_hash = "aa" * 16
identity_dir = os.path.join(temp_dir, "identities", new_hash)
os.makedirs(identity_dir)
identity_file = os.path.join(identity_dir, "identity")
@@ -115,7 +115,7 @@ async def test_hotswap_identity_success(mock_rns, temp_dir):
f.write(b"new_private_key")
new_id_instance = MagicMock()
- new_id_instance.hash = b"new_hash_32_bytes_long_012345678"
+ new_id_instance.hash = bytes.fromhex(new_hash)
mock_rns["Identity"].from_file.return_value = new_id_instance
# Configure mock context
@@ -157,7 +157,7 @@ async def test_hotswap_identity_keep_alive(mock_rns, temp_dir):
)
# Setup new identity
- new_hash = "new_hash_123"
+ new_hash = "bb" * 16
identity_dir = os.path.join(temp_dir, "identities", new_hash)
os.makedirs(identity_dir)
identity_file = os.path.join(identity_dir, "identity")
@@ -165,7 +165,7 @@ async def test_hotswap_identity_keep_alive(mock_rns, temp_dir):
f.write(b"new_private_key")
new_id_instance = MagicMock()
- new_id_instance.hash = b"new_hash_32_bytes_long_012345678"
+ new_id_instance.hash = bytes.fromhex(new_hash)
mock_rns["Identity"].from_file.return_value = new_id_instance
# Configure mock context
@@ -196,8 +196,8 @@ async def test_hotswap_identity_file_missing(mock_rns, temp_dir):
reticulum_config_dir=temp_dir,
)
- # Attempt hotswap with non-existent hash
- result = await app.hotswap_identity("non_existent_hash")
+ # Attempt hotswap with valid hex that has no on-disk identity
+ result = await app.hotswap_identity("cc" * 16)
assert result is False
@@ -211,7 +211,7 @@ async def test_hotswap_identity_corrupted(mock_rns, temp_dir):
)
# Setup "corrupted" identity
- new_hash = "corrupted_hash"
+ new_hash = "dd" * 16
identity_dir = os.path.join(temp_dir, "identities", new_hash)
os.makedirs(identity_dir)
identity_file = os.path.join(identity_dir, "identity")
@@ -240,7 +240,7 @@ async def test_hotswap_identity_recovery(mock_rns, temp_dir):
f.write(b"initial_private_key")
# Setup new identity
- new_hash = "new_hash_123"
+ new_hash = "ee" * 16
identity_dir = os.path.join(temp_dir, "identities", new_hash)
os.makedirs(identity_dir)
identity_file = os.path.join(identity_dir, "identity")
@@ -248,7 +248,7 @@ async def test_hotswap_identity_recovery(mock_rns, temp_dir):
f.write(b"new_private_key")
new_id_instance = MagicMock()
- new_id_instance.hash = b"new_hash_32_bytes_long_012345678"
+ new_id_instance.hash = bytes.fromhex(new_hash)
mock_rns["Identity"].from_file.return_value = new_id_instance
# Mock setup_identity to fail first time (after hotswap start),
@@ -277,7 +277,7 @@ async def test_hotswap_identity_ultimate_failure_emergency_identity(mock_rns, te
)
# Setup new identity
- new_hash = "new_hash_123"
+ new_hash = "ff" * 16
identity_dir = os.path.join(temp_dir, "identities", new_hash)
os.makedirs(identity_dir)
identity_file = os.path.join(identity_dir, "identity")
@@ -285,7 +285,7 @@ async def test_hotswap_identity_ultimate_failure_emergency_identity(mock_rns, te
f.write(b"new_private_key")
new_id_instance = MagicMock()
- new_id_instance.hash = b"new_hash_32_bytes_long_012345678"
+ new_id_instance.hash = bytes.fromhex(new_hash)
mock_rns["Identity"].from_file.return_value = new_id_instance
# Mock setup_identity to fail ALL THE TIME
@@ -294,12 +294,12 @@ async def test_hotswap_identity_ultimate_failure_emergency_identity(mock_rns, te
app.websocket_broadcast = AsyncMock()
# Mock create_identity to return a new hash
- emergency_hash = "emergency_hash_456"
+ emergency_hash = "11" * 16
app.create_identity = MagicMock(return_value={"hash": emergency_hash})
# Mock RNS.Identity.from_file for the emergency identity
emergency_id = MagicMock()
- emergency_id.hash = b"emergency_hash_32_bytes_long_012"
+ emergency_id.hash = bytes.fromhex(emergency_hash)
# Ensure from_file returns the new identity when called for the emergency one
def side_effect_from_file(path):
diff --git a/tests/backend/test_rns_lifecycle.py b/tests/backend/test_rns_lifecycle.py
index 7dadb5c7..52bebba5 100644
--- a/tests/backend/test_rns_lifecycle.py
+++ b/tests/backend/test_rns_lifecycle.py
@@ -519,7 +519,7 @@ async def test_hotswap_identity(mock_rns, temp_dir):
)
# Create a mock identity file for the new identity
- new_identity_hash = "new_hash"
+ new_identity_hash = "22" * 16
new_identity_dir = os.path.join(temp_dir, "identities", new_identity_hash)
os.makedirs(new_identity_dir)
with open(os.path.join(new_identity_dir, "identity"), "wb") as f:
diff --git a/tests/backend/test_security_path_jail_regressions.py b/tests/backend/test_security_path_jail_regressions.py
index 19226641..d5966913 100644
--- a/tests/backend/test_security_path_jail_regressions.py
+++ b/tests/backend/test_security_path_jail_regressions.py
@@ -159,13 +159,22 @@ def test_plugin_wasm_resolve_does_not_delete_outside_install(tmp_path):
@pytest.mark.asyncio
-async def test_rncp_send_path_jails_and_blocks_identity(tmp_path):
+async def test_rncp_send_path_jails_and_blocks_identity(tmp_path, monkeypatch):
handler = RNCPHandler(MagicMock(), MagicMock(), str(tmp_path))
allowed = tmp_path / "payload.bin"
allowed.write_bytes(b"data")
identity_file = tmp_path / "identity"
identity_file.write_bytes(b"secret-key")
- outside = tmp_path.parent / "outside-rncp.bin"
+
+ # Keep home jail separate from pytest tmp so sibling paths do not pass.
+ fake_home = tmp_path / "home"
+ fake_home.mkdir()
+ monkeypatch.setenv("HOME", str(fake_home))
+ monkeypatch.setattr(os.path, "expanduser", lambda p: str(fake_home) if p == "~" else p)
+
+ outside_root = tmp_path.parent / "rncp-outside-root"
+ outside_root.mkdir(exist_ok=True)
+ outside = outside_root / "outside-rncp.bin"
outside.write_bytes(b"nope")
assert handler._resolve_send_path(str(allowed)).endswith("payload.bin")
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────